package main

import (
	"log"

	"github.com/lxn/walk"
	. "github.com/lxn/walk/declarative"
)

type MyMainWindow struct {
	*walk.MainWindow
}

func main() {
	var (
		ltj     *walk.NumberEdit
		lte     *walk.LineEdit
		ltphone *walk.LineEdit
		//ep         *walk.LineErrorPresenter
		addUserBtn *walk.PushButton
	)
	mw := new(MyMainWindow)
	if err := (MainWindow{
		AssignTo: &mw.MainWindow,
		Title:    "华中师范大学多媒体教学使用满意度调查",
		//ScreenCenter: true, // 屏幕居中不能用
		MinSize: Size{300, 260},
		Layout:  VBox{Spacing: 2}, //VBox{},

		Children: []Widget{
			Composite{
				Layout: Grid{Columns: 2, Spacing: 10},
				Children: []Widget{
					VSplitter{
						Children: []Widget{
							Label{
								MinSize: Size{18, 0},
								Text:    "工号:",
							},
						},
					},
					VSplitter{
						Children: []Widget{
							NumberEdit{
								AssignTo: &ltj,
								Value:    Bind("JobNumber", Range{1, 10}),
							},
						},
					},
					VSplitter{
						Children: []Widget{
							Label{
								MinSize: Size{18, 0},
								Text:    "邮箱:",
							},
						},
					},
					VSplitter{
						Children: []Widget{
							LineEdit{
								AssignTo: &lte,
								MinSize:  Size{160, 0},
								Text:     Bind("Email"),
							},
						},
					},
					VSplitter{
						Children: []Widget{
							Label{
								MinSize: Size{18, 0},
								Text:    "手机:",
							},
						},
					},
					VSplitter{
						Children: []Widget{
							LineEdit{
								AssignTo: &ltphone,
								MinSize:  Size{160, 0},
								Text:     Bind("Phone"),
							},
						},
					},
					// VSplitter{},
					VSplitter{
						ColumnSpan: 2,
						MinSize:    Size{100, 0},
						Children: []Widget{
							/*LineErrorPresenter{
								AssignTo:   &ep,
								ColumnSpan: 2,
							},*/
							PushButton{
								AssignTo:  &addUserBtn,
								MinSize:   Size{90, 0},
								Text:      "提交",
								OnClicked: mw.submit,
							},
						},
					},
				},
			},
		},
	}.Create()); err != nil {
		log.Fatal(err)
	}
	mw.Run()
}
func (mw *MyMainWindow) submit() {
	log.Println(mw.Size())
	walk.MsgBox(mw, "错误提示", "？", walk.MsgBoxIconError)
	walk.MsgBox(mw, "提示信息", "保存用户成功.", walk.MsgBoxIconInformation)
}
